package com.codingfuture.erp_system.web.controller;

import com.codingfuture.erp_system.dto.PageData;
import com.codingfuture.erp_system.dto.RoleDto;
import com.codingfuture.erp_system.dto.RolePwdDto;
import com.codingfuture.erp_system.service.RoleService;
import com.codingfuture.erp_system.util.Result;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/v2")
@RestController
public class RolePasswordController {

    @Autowired
    private RoleService roleService;

    //重置密码 渲染
    @GetMapping("/emp_listByPage/listByPage")
    public Result findByAll(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int rows) {

        Page<Object> page1 = PageHelper.startPage(page, rows);
        List<RoleDto> list = roleService.findByAll();
        PageData<RoleDto> data = new PageData<>(list, page1.getTotal());
        return Result.ok(data);
    }

    //修改密码
    @PostMapping("/emp_updatePwd_reset/update")
    public Result update(RolePwdDto rolePwdDto) {
        Boolean result = roleService.update(rolePwdDto);
        return result ? Result.ok() : Result.error(201, "错误");
    }


}
